package com.alipear.shopcredit.common.view.wrapper;

import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.alipear.ppwhere.common.R;


/**
 * Created by zoulinlin on 2015/3/27.
 */
public class TitleBarViewWrapper extends ViewWrapperCommon{
    /*Wrapper R.layout.listview_cell_view*/
    private TextView mTitleView;
    private View  mLeftButton;
    private Button mRightButton;

    public TextView getTitleView() {
        return mTitleView;
    }

    public View getLeftButton() {
        return mLeftButton;
    }

    public Button getRightButton() {
        return mRightButton;
    }

    public  TitleBarViewWrapper( View textView) {
        super(textView);
        mTitleView = (TextView)textView;
        enableLeftButton(false);
        enableRightButton(false);
    }

    public  TitleBarViewWrapper(final Activity activity, View rootView) {
        super(rootView);
        mTitleView = (TextView)rootView.findViewById(R.id.title_text_view);
        mLeftButton  = rootView.findViewById(R.id.left_button);
        if (mLeftButton != null) {
            mLeftButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    activity.finish();
                }
            });
        }
        mRightButton = (Button)rootView.findViewById(R.id.right_button);
    }

    public TitleBarViewWrapper setTitle(int titleRes) {
        mTitleView.setText(titleRes);
        return this;
    }

    public TitleBarViewWrapper setTitle(String title) {
        mTitleView.setText(title);
        return this;
    }

    public TitleBarViewWrapper enableTitleBar(boolean flag) {
        if (mTitleView != null) {
            mTitleView.setVisibility(flag ? View.VISIBLE: View.GONE);
        }
        return this;
    }

    public TitleBarViewWrapper enableLeftButton(boolean flag) {
        if (mLeftButton != null) {
            mLeftButton.setVisibility(flag ? View.VISIBLE: View.GONE);
        }
        return this;
    }

    public TitleBarViewWrapper setLeftButtonListener( View.OnClickListener listener) {
        if (mLeftButton != null) {
            mLeftButton.setOnClickListener(listener);
        }
        return this;
    }


    public TitleBarViewWrapper enableRightButton(boolean flag) {
        if (mRightButton != null) {
            mRightButton.setVisibility(flag ? View.VISIBLE: View.GONE);
        }
        return this;
    }

    public TitleBarViewWrapper setRightButtonText(String text) {
        if (mRightButton != null) {
            mRightButton.setText(text);
        }
        return this;
    }

    public TitleBarViewWrapper setRightButtonText(int  text) {
        if (mRightButton != null) {
            mRightButton.setText(text);
        }
        return this;
    }

    public TitleBarViewWrapper setRightButtonListener( View.OnClickListener listener) {
        if (mRightButton != null) {
            mRightButton.setOnClickListener(listener);
        }
        return this;
    }

    public TitleBarViewWrapper setRightButtonBackground(int resId) {
        if (mRightButton != null) {
            mRightButton.setBackgroundResource(resId);
        }
        return this;
    }
}
